{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div id=\"interact-js-shim\">\n",
       "    <script charset=\"utf-8\">\n",
       "(function (IPython, $, _, MathJax) {\n",
       "    $.event.special.destroyed = {\n",
       "\tremove: function(o) {\n",
       "\t    if (o.handler) {\n",
       "\t\to.handler.apply(this, arguments)\n",
       "\t    }\n",
       "\t}\n",
       "    }\n",
       "\n",
       "    var OutputArea = IPython.version >= \"4.0.0\" ? require(\"notebook/js/outputarea\").OutputArea : IPython.OutputArea;\n",
       "\n",
       "    var redrawValue = function (container, type, val) {\n",
       "\tvar selector = $(\"<div/>\");\n",
       "\tvar oa = new OutputArea(_.extend(selector, {\n",
       "\t    selector: selector,\n",
       "\t    prompt_area: true,\n",
       "\t    events: IPython.events,\n",
       "\t    keyboard_manager: IPython.keyboard_manager\n",
       "\t})); // Hack to work with IPython 2.1.0\n",
       "\n",
       "\tswitch (type) {\n",
       "\tcase \"image/png\":\n",
       "            var _src = 'data:' + type + ';base64,' + val;\n",
       "\t    $(container).find(\"img\").attr('src', _src);\n",
       "\t    break;\n",
       "\tdefault:\n",
       "\t    var toinsert = OutputArea.append_map[type].apply(\n",
       "\t\toa, [val, {}, selector]\n",
       "\t    );\n",
       "\t    $(container).empty().append(toinsert.contents());\n",
       "\t    selector.remove();\n",
       "\t}\n",
       "\tif (type === \"text/latex\" && MathJax) {\n",
       "\t    MathJax.Hub.Queue([\"Typeset\", MathJax.Hub, toinsert.get(0)]);\n",
       "\t}\n",
       "    }\n",
       "\n",
       "\n",
       "    $(document).ready(function() {\n",
       "\tfunction initComm(evt, data) {\n",
       "\t    var comm_manager = data.kernel.comm_manager;\n",
       "        //_.extend(comm_manager.targets, require(\"widgets/js/widget\"))\n",
       "\t    comm_manager.register_target(\"Signal\", function (comm) {\n",
       "            comm.on_msg(function (msg) {\n",
       "                //Widgets.log(\"message received\", msg);\n",
       "                var val = msg.content.data.value;\n",
       "                $(\".signal-\" + comm.comm_id).each(function() {\n",
       "                var type = $(this).data(\"type\");\n",
       "                if (val[type]) {\n",
       "                    redrawValue(this, type, val[type], type);\n",
       "                }\n",
       "                });\n",
       "                delete val;\n",
       "                delete msg.content.data.value;\n",
       "            });\n",
       "\t    });\n",
       "\n",
       "\t    // coordingate with Comm and redraw Signals\n",
       "\t    // XXX: Test using Reactive here to improve performance\n",
       "\t    $([IPython.events]).on(\n",
       "\t\t'output_appended.OutputArea', function (event, type, value, md, toinsert) {\n",
       "\t\t    if (md && md.reactive) {\n",
       "                // console.log(md.comm_id);\n",
       "                toinsert.addClass(\"signal-\" + md.comm_id);\n",
       "                toinsert.data(\"type\", type);\n",
       "                // Signal back indicating the mimetype required\n",
       "                var comm_manager = IPython.notebook.kernel.comm_manager;\n",
       "                var comm = comm_manager.comms[md.comm_id];\n",
       "                comm.then(function (c) {\n",
       "                    c.send({action: \"subscribe_mime\",\n",
       "                       mime: type});\n",
       "                    toinsert.bind(\"destroyed\", function() {\n",
       "                        c.send({action: \"unsubscribe_mime\",\n",
       "                               mime: type});\n",
       "                    });\n",
       "                })\n",
       "\t\t    }\n",
       "\t    });\n",
       "\t}\n",
       "\n",
       "\ttry {\n",
       "\t    // try to initialize right away. otherwise, wait on the status_started event.\n",
       "\t    initComm(undefined, IPython.notebook);\n",
       "\t} catch (e) {\n",
       "\t    $([IPython.events]).on('kernel_created.Kernel kernel_created.Session', initComm);\n",
       "\t}\n",
       "    });\n",
       "})(IPython, jQuery, _, MathJax);\n",
       "</script>\n",
       "    <script>\n",
       "        window.interactLoadedFlag = true\n",
       "       $(\"#interact-js-shim\").bind(\"destroyed\", function () {\n",
       "           if (window.interactLoadedFlag) {\n",
       "               console.warn(\"JavaScript required by Interact will be removed if you remove this cell or run using Interact more than once.\")\n",
       "           }\n",
       "       })\n",
       "       $([IPython.events]).on(\"kernel_starting.Kernel kernel_restarting.Kernel\", function () { window.interactLoadedFlag = false })\n",
       "   </script>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "using FileIO\n",
    "using MeshIO\n",
    "using GeometryTypes\n",
    "using StaticArrays\n",
    "using Plots\n",
    "gr()\n",
    "using DrakeVisualizer\n",
    "using Interact"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Process(`drake-visualizer`, ProcessRunning)"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DrakeVisualizer.new_window()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "HomogenousMesh(\n",
       "    normals: 27xGeometryTypes.Normal{3,Float32},     vertices: 27xFixedSizeArrays.Point{3,Float32},     faces: 50xGeometryTypes.Face{3,UInt32,-1}, )\n"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mesh = load(\"/Users/rdeits/locomotion/drake-distro/drake/examples/Atlas/urdf/meshes/pelvis_chull.obj\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DrakeVisualizer.Visualizer(DrakeVisualizer.Robot(DrakeVisualizer.Link[DrakeVisualizer.Link(DrakeVisualizer.GeometryData[DrakeVisualizer.GeometryData{CoordinateTransformations.IdentityTransformation,GeometryTypes.HomogenousMesh{FixedSizeArrays.Point{3,Float32},GeometryTypes.Face{3,UInt32,-1},GeometryTypes.Normal{3,Float32},Void,Void,Void,Void}}(HomogenousMesh(\n",
       "    normals: 27xGeometryTypes.Normal{3,Float32},     vertices: 27xFixedSizeArrays.Point{3,Float32},     faces: 50xGeometryTypes.Face{3,UInt32,-1}, )\n",
       ",CoordinateTransformations.IdentityTransformation(),RGBA{Float64}(1.0,0.0,0.0,0.5))],\"link\")]),1,PyLCM.LCM(PyObject <LCM object at 0x31b15cd50>))"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Visualizer(mesh)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import AdaptiveDistanceFields"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: replacing module AdaptiveDistanceFields\n",
      "WARNING: Method definition needs_refinement(RegionTrees.Cell, Any, Any, Any) in module AdaptiveDistanceFields at /Users/rdeits/.julia/v0.5/AdaptiveDistanceFields/src/adaptivesampling.jl:12 overwritten in module AdaptiveDistanceFields at /Users/rdeits/.julia/v0.5/AdaptiveDistanceFields/src/adaptivesampling.jl:12.\n",
      "WARNING: Method definition convert(Type{#S<:StaticArrays.SVector}, GeometryTypes.Simplex{#N<:Any, T<:Any}) in module ConvexMesh at /Users/rdeits/.julia/v0.5/AdaptiveDistanceFields/src/meshdistance.jl:25 overwritten in module ConvexMesh at /Users/rdeits/.julia/v0.5/AdaptiveDistanceFields/src/meshdistance.jl:25.\n"
     ]
    }
   ],
   "source": [
    "reload(\"AdaptiveDistanceFields\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(::#7) (generic function with 1 method)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = AdaptiveDistanceFields.ConvexMesh.signed_distance(mesh)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(::AdaptiveDistanceField) (generic function with 1 method)"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "origin = SVector(-2., -2, -2)\n",
    "widths = SVector(4., 4, 4)\n",
    "adaptive = AdaptiveDistanceFields.AdaptiveDistanceField(s, origin, widths, 1e-2, 1e-2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "verts = Point{3, Float64}[]\n",
    "faces = Face{3, Int, 0}[]\n",
    "for cell in RegionTrees.allcells(adaptive.root)\n",
    "    for face in RegionTrees.faces(cell.boundary)\n",
    "        i = length(verts)\n",
    "        for vert in face\n",
    "            push!(verts, Point(vert[1], vert[2], vert[3]))\n",
    "        end\n",
    "#         push!(faces, Face(i+1, i+2, i+1))\n",
    "#         push!(faces, Face(i+1, i+3, i+1))\n",
    "#         push!(faces, Face(i+2, i+4, i+2))\n",
    "#         push!(faces, Face(i+3, i+4, i+3))\n",
    "        push!(faces, Face(i+1, i+2, i+4))\n",
    "        push!(faces, Face(i+4, i+3, i+1))\n",
    "    end\n",
    "end\n",
    "\n",
    "boxmesh = HomogenousMesh(verts, faces)\n",
    "Visualizer(boxmesh);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\" viewBox=\"0 0 600 400\">\n",
       "<defs>\n",
       "  <clipPath id=\"clip00\">\n",
       "    <rect x=\"0\" y=\"0\" width=\"600\" height=\"400\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<polygon clip-path=\"url(#clip00)\" points=\"\n",
       "0,400 600,400 600,0 0,0 \n",
       "  \" fill=\"#ffffff\" fill-opacity=\"1\"/>\n",
       "<defs>\n",
       "  <clipPath id=\"clip01\">\n",
       "    <rect x=\"120\" y=\"0\" width=\"421\" height=\"400\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<polygon clip-path=\"url(#clip00)\" points=\"\n",
       "43.4296,381.015 596.063,381.015 596.063,3.93701 43.4296,3.93701 \n",
       "  \" fill=\"#ffffff\" fill-opacity=\"1\"/>\n",
       "<defs>\n",
       "  <clipPath id=\"clip02\">\n",
       "    <rect x=\"43\" y=\"3\" width=\"553\" height=\"378\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:0.5; fill:none\" stroke-dasharray=\"1, 2\" points=\"\n",
       "  43.4296,375.359 43.4296,9.59318 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:0.5; fill:none\" stroke-dasharray=\"1, 2\" points=\"\n",
       "  181.588,375.359 181.588,9.59318 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:0.5; fill:none\" stroke-dasharray=\"1, 2\" points=\"\n",
       "  319.746,375.359 319.746,9.59318 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:0.5; fill:none\" stroke-dasharray=\"1, 2\" points=\"\n",
       "  457.905,375.359 457.905,9.59318 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:0.5; fill:none\" stroke-dasharray=\"1, 2\" points=\"\n",
       "  596.063,375.359 596.063,9.59318 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:0.5; fill:none\" stroke-dasharray=\"1, 2\" points=\"\n",
       "  51.7191,381.015 587.773,381.015 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:0.5; fill:none\" stroke-dasharray=\"1, 2\" points=\"\n",
       "  51.7191,318.169 587.773,318.169 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:0.5; fill:none\" stroke-dasharray=\"1, 2\" points=\"\n",
       "  51.7191,255.322 587.773,255.322 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:0.5; fill:none\" stroke-dasharray=\"1, 2\" points=\"\n",
       "  51.7191,192.476 587.773,192.476 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:0.5; fill:none\" stroke-dasharray=\"1, 2\" points=\"\n",
       "  51.7191,129.63 587.773,129.63 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:0.5; fill:none\" stroke-dasharray=\"1, 2\" points=\"\n",
       "  51.7191,66.7833 587.773,66.7833 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:0.5; fill:none\" stroke-dasharray=\"1, 2\" points=\"\n",
       "  51.7191,3.93701 587.773,3.93701 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  43.4296,381.015 596.063,381.015 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  43.4296,381.015 43.4296,375.359 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  181.588,381.015 181.588,375.359 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  319.746,381.015 319.746,375.359 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  457.905,381.015 457.905,375.359 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  596.063,381.015 596.063,375.359 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  43.4296,381.015 43.4296,3.93701 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  43.4296,381.015 51.7191,381.015 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  43.4296,318.169 51.7191,318.169 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  43.4296,255.322 51.7191,255.322 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  43.4296,192.476 51.7191,192.476 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  43.4296,129.63 51.7191,129.63 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  43.4296,66.7833 51.7191,66.7833 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  43.4296,3.93701 51.7191,3.93701 \n",
       "  \"/>\n",
       "<g clip-path=\"url(#clip00)\">\n",
       "<text style=\"fill:#00002d; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:middle;\" transform=\"rotate(0, 43.4296, 393.015)\" x=\"43.4296\" y=\"393.015\">-2</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip00)\">\n",
       "<text style=\"fill:#00002d; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:middle;\" transform=\"rotate(0, 181.588, 393.015)\" x=\"181.588\" y=\"393.015\">-1</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip00)\">\n",
       "<text style=\"fill:#00002d; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:middle;\" transform=\"rotate(0, 319.746, 393.015)\" x=\"319.746\" y=\"393.015\">0</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip00)\">\n",
       "<text style=\"fill:#00002d; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:middle;\" transform=\"rotate(0, 457.905, 393.015)\" x=\"457.905\" y=\"393.015\">1</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip00)\">\n",
       "<text style=\"fill:#00002d; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:middle;\" transform=\"rotate(0, 596.063, 393.015)\" x=\"596.063\" y=\"393.015\">2</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip00)\">\n",
       "<text style=\"fill:#00002d; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:end;\" transform=\"rotate(0, 42.2296, 385.515)\" x=\"42.2296\" y=\"385.515\">-1.0</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip00)\">\n",
       "<text style=\"fill:#00002d; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:end;\" transform=\"rotate(0, 42.2296, 322.669)\" x=\"42.2296\" y=\"322.669\">-0.5</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip00)\">\n",
       "<text style=\"fill:#00002d; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:end;\" transform=\"rotate(0, 42.2296, 259.822)\" x=\"42.2296\" y=\"259.822\">0.0</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip00)\">\n",
       "<text style=\"fill:#00002d; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:end;\" transform=\"rotate(0, 42.2296, 196.976)\" x=\"42.2296\" y=\"196.976\">0.5</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip00)\">\n",
       "<text style=\"fill:#00002d; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:end;\" transform=\"rotate(0, 42.2296, 134.13)\" x=\"42.2296\" y=\"134.13\">1.0</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip00)\">\n",
       "<text style=\"fill:#00002d; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:end;\" transform=\"rotate(0, 42.2296, 71.2833)\" x=\"42.2296\" y=\"71.2833\">1.5</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip00)\">\n",
       "<text style=\"fill:#00002d; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:end;\" transform=\"rotate(0, 42.2296, 8.43701)\" x=\"42.2296\" y=\"8.43701\">2.0</text>\n",
       "</g>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#0099ff; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  43.4296,23.2981 54.7078,33.5576 65.986,43.8171 77.2643,54.0766 88.5425,64.3361 99.8207,74.5955 111.099,84.855 122.377,95.1145 133.655,105.374 144.934,115.633 \n",
       "  156.212,125.893 167.49,136.152 178.768,146.412 190.047,156.671 201.325,166.931 212.603,177.19 223.881,187.45 235.16,197.709 246.438,207.969 257.716,218.228 \n",
       "  268.994,228.488 280.272,238.747 291.551,249.007 302.829,259.266 314.107,269.526 325.385,267.265 336.664,261.923 347.942,251.665 359.22,241.407 370.498,231.15 \n",
       "  381.777,220.892 393.055,210.635 404.333,200.377 415.611,190.119 426.889,179.862 438.168,169.604 449.446,159.346 460.724,149.087 472.002,138.828 483.281,128.568 \n",
       "  494.559,118.309 505.837,108.049 517.115,97.789 528.394,87.5291 539.672,77.269 550.95,67.009 562.228,56.7488 573.507,46.4886 584.785,36.2284 596.063,25.9681 \n",
       "  \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip02)\" style=\"stroke:#e9746a; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  43.4296,23.2981 54.7078,33.5576 65.986,43.8171 77.2643,54.0766 88.5425,64.3361 99.8207,74.5955 111.099,84.855 122.377,95.1145 133.655,105.374 144.934,115.633 \n",
       "  156.212,125.893 167.49,136.152 178.768,146.412 190.047,156.671 201.325,166.931 212.603,177.19 223.881,187.45 235.16,197.709 246.438,207.969 257.716,218.228 \n",
       "  268.994,228.488 280.272,238.747 291.551,249.007 302.829,259.266 314.107,269.267 325.385,267.265 336.664,261.866 347.942,251.665 359.22,241.407 370.498,231.15 \n",
       "  381.777,220.892 393.055,210.635 404.333,200.377 415.611,190.119 426.889,179.862 438.168,169.604 449.446,159.345 460.724,149.087 472.002,138.827 483.281,128.568 \n",
       "  494.559,118.309 505.837,108.049 517.115,97.7889 528.394,87.5291 539.672,77.269 550.95,67.0089 562.228,56.7488 573.507,46.4886 584.785,36.2284 596.063,25.9681 \n",
       "  \n",
       "  \"/>\n",
       "<polygon clip-path=\"url(#clip00)\" points=\"\n",
       "505.547,70.177 578.063,70.177 578.063,24.817 505.547,24.817 \n",
       "  \" fill=\"#ffffff\" fill-opacity=\"1\"/>\n",
       "<polyline clip-path=\"url(#clip00)\" style=\"stroke:#00002d; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  505.547,70.177 578.063,70.177 578.063,24.817 505.547,24.817 505.547,70.177 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip00)\" style=\"stroke:#0099ff; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  511.547,39.937 547.547,39.937 \n",
       "  \"/>\n",
       "<g clip-path=\"url(#clip00)\">\n",
       "<text style=\"fill:#00002d; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:start;\" transform=\"rotate(0, 553.547, 44.437)\" x=\"553.547\" y=\"44.437\">y1</text>\n",
       "</g>\n",
       "<polyline clip-path=\"url(#clip00)\" style=\"stroke:#e9746a; stroke-width:0.8; stroke-opacity:1; fill:none\" points=\"\n",
       "  511.547,55.057 547.547,55.057 \n",
       "  \"/>\n",
       "<g clip-path=\"url(#clip00)\">\n",
       "<text style=\"fill:#00002d; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:start;\" transform=\"rotate(0, 553.547, 59.557)\" x=\"553.547\" y=\"59.557\">y2</text>\n",
       "</g>\n",
       "</svg>\n"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xs = linspace(-2, 2)\n",
    "plot(xs, [s(SVector(x, 0.0, 0.0)) for x in xs], ylim=(-1, 2))\n",
    "plot!(xs, [adaptive(SVector(x, 0.0, 0.0)) for x in xs], ylim=(-1, 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [],
      "text/plain": [
       "Interact.Slider{Float64}(Signal{Float64}(0.0, nactions=0),\"isolevel\",0.0,linspace(-1.0,1.0,101),\".3f\",true)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "DrakeVisualizer.Visualizer(DrakeVisualizer.Robot(DrakeVisualizer.Link[DrakeVisualizer.Link(DrakeVisualizer.GeometryData[DrakeVisualizer.GeometryData{CoordinateTransformations.IdentityTransformation,GeometryTypes.HomogenousMesh{FixedSizeArrays.Point{3,Float64},GeometryTypes.Face{3,Int64,0},Void,Void,Void,Void,Void}}(HomogenousMesh(\n",
       "    vertices: 156xFixedSizeArrays.Point{3,Float64},     faces: 308xGeometryTypes.Face{3,Int64,0}, )\n",
       ",CoordinateTransformations.IdentityTransformation(),RGBA{Float64}(1.0,0.0,0.0,0.5))],\"link\")]),1,PyLCM.LCM(PyObject <LCM object at 0x31b15cc60>))"
      ]
     },
     "execution_count": 37,
     "metadata": {
      "comm_id": "3a4eeaad-2bb3-4d8b-b14d-07c747ab59d7",
      "reactive": true
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@manipulate for isolevel in linspace(-1.0, 1.0, 101)\n",
    "    Visualizer(contour_mesh(s, SVector(-1., -1, -1), SVector(1., 1, 1), isolevel))\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [],
      "text/plain": [
       "Interact.Slider{Float64}(Signal{Float64}(0.0, nactions=0),\"isolevel\",0.0,linspace(-1.0,1.0,101),\".3f\",true)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "DrakeVisualizer.Visualizer(DrakeVisualizer.Robot(DrakeVisualizer.Link[DrakeVisualizer.Link(DrakeVisualizer.GeometryData[DrakeVisualizer.GeometryData{CoordinateTransformations.IdentityTransformation,GeometryTypes.HomogenousMesh{FixedSizeArrays.Point{3,Float64},GeometryTypes.Face{3,Int64,0},Void,Void,Void,Void,Void}}(HomogenousMesh(\n",
       "    vertices: 3890xFixedSizeArrays.Point{3,Float64},     faces: 7776xGeometryTypes.Face{3,Int64,0}, )\n",
       ",CoordinateTransformations.IdentityTransformation(),RGBA{Float64}(1.0,0.0,0.0,0.5))],\"link\")]),1,PyLCM.LCM(PyObject <LCM object at 0x31b15ce70>))"
      ]
     },
     "execution_count": 38,
     "metadata": {
      "comm_id": "e0ff1ca9-9f5d-4a13-9de4-276cd6fc867c",
      "reactive": true
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@manipulate for isolevel in linspace(-1.0, 1.0, 101)\n",
    "    Visualizer(contour_mesh(adaptive, SVector(-1., -1, -1), SVector(1., 1, 1), isolevel, 0.02))\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "using BenchmarkTools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "BenchmarkTools.Trial: \n",
       "  memory estimate:  0.00 bytes\n",
       "  allocs estimate:  0\n",
       "  --------------\n",
       "  minimum time:     83.116 ns (0.00% GC)\n",
       "  median time:      85.980 ns (0.00% GC)\n",
       "  mean time:        96.864 ns (0.00% GC)\n",
       "  maximum time:     402.611 ns (0.00% GC)\n",
       "  --------------\n",
       "  samples:          10000\n",
       "  evals/sample:     963\n",
       "  time tolerance:   5.00%\n",
       "  memory tolerance: 1.00%"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p = SVector(0.25, 0, 0)\n",
    "@benchmark $adaptive($p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 0.5.0",
   "language": "julia",
   "name": "julia-0.5"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "0.5.0"
  },
  "widgets": {
   "state": {
    "ba6ee692-f0ec-43af-911b-812ac10acea7": {
     "views": [
      {
       "cell_index": 10
      }
     ]
    },
    "d8acbcb9-7d83-4572-82df-d0f7133bb355": {
     "views": [
      {
       "cell_index": 9
      }
     ]
    }
   },
   "version": "1.2.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
